<template>
  <div class="ChildPage TablePage" v-loading="loading">
    <vb-page ref="page">
      <template #headerSearch-append="scope">
        <el-select v-model="scope.searchForm.stockNo" clearable placeholder="请选择仓库" style="margin-right: 10px" size="small">
          <el-option v-for="item in dataList" :key="item.fNumber" :label="item.fName" :value="item.fNumber"></el-option>
        </el-select>

      </template>
      <template #table-handle-edit="scope">
        <el-button type="warning" size="small"  icon="el-icon-download" @click="downloadRegular(scope.row.billNo)">导出</el-button>
      </template>
      <template #table-boxCount="scope">
        {{ scope.row.boxCount || '-' }}
      </template>
      <template #table-count="scope">
        {{ scope.row.count? `${Number(scope.row.count.toFixed(4))}${scope.row.unit}`: '-' }}
      </template>
      <template #table-stockNo="scope">
        {{ getStockName(scope.row.stockNo) }}
      </template>

      <!--      <template #table-handle-prepend="scope">-->
      <!--        <el-button size="mini" type="text" icon="el-icon-edit" @click="gotoDetail(scope.row.billNo, scope.row.stockNo)">查看</el-button>-->
      <!--      </template>-->
    </vb-page>
  </div>
</template>

<script>
export default {
  data() {
    return {
      reloadMaterial: false,
      materialList: [],
      stockList: [],
      dataList: [],
    }
  },
  async mounted() {
    await this.getStock()
    await this.selectStock()
  },
  methods: {
    async doSyncInventory(){
      this.loading = true
      try {
        let res = await this.callApi('sync_inventory_serial')
        if (!res.res) return
        // this.dataList = res.data
      } finally {
        this.loading = false
      }
    },
    async selectStock() {
      this.loading = true
      try {
        let res = await this.callApi('get_stock')
        if (!res.res) return
        this.dataList = res.data
      } finally {
        this.loading = false
      }
    },
    async downloadRegular(billNo) {
      this.loading = true
      try {
        let res = await this.callApi('download_regular', {billNo : billNo})
        if (!res.res) return
      } finally {
        this.loading = false
      }
    },

    async getStock() {
      this.loading = true;
      try {
        let res = await this.$api.getChildDictionaryListByKeys({
          keys: ['stock']
        });
        if (!res.res) return;
        this.stockList = res.stock;
      } finally {
        this.loading = false;
      }
    },
    /**
     * 获取状态名
     */
    getStockName(val) {
      if (this.stockList && this.stockList.length > 0) {
        for(let i = 0; i < this.stockList.length; i++) {
          if (this.stockList[i].key === val) {
            return this.stockList[i].name + ':' + this.stockList[i].key;
          }
        }
      }
      return '';
    }
  }
}
</script>

<style scoped>
</style>
